﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Media;

namespace UBCon.Core
{
    public static class CommonUtilities
    {
        /// <summary>
        /// Recursively finds root visual of specified control.
        /// </summary>
        /// <param name="node">Control of which root parent must be found.</param>
        /// <returns>Type: System.Windows.DependencyObject. Root visual control.</returns>
        public static DependencyObject GetVisualRoot(DependencyObject node)
        {
            DependencyObject parent = null;

            if (node != null)
            {
                parent = VisualTreeHelper.GetParent(node);

                if (parent != null)
                {
                    return GetVisualRoot(parent);
                }
                else
                {
                    return node;
                }
            }

            return null;
        }


    }
}
